|
RAIS
3.2
|
00001 00028 using System; 00029 using System.Collections.Generic; 00030 using System.Data; 00031 using System.Text; 00032 00033 using DataRoleAttributes = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.DataRoleAttribute>; 00034 00035 namespace RAIS.Common.UserManagement 00036 { 00037 #region DataRole class 00038 00041 public class DataRole : DBObject 00042 { 00043 //********************************************************************* 00044 #region Fields 00045 DataRoleAttributes attributes = new DataRoleAttributes(); 00046 DataRoleAttributes addedAttributes = new DataRoleAttributes(); 00047 DataRoleAttributes removedAttributes = new DataRoleAttributes(); 00048 bool modified = false; 00049 #endregion 00050 //********************************************************************* 00051 #region Properties 00052 00055 public DataRoleAttributes Attributes 00056 { 00057 get { return this.attributes; } 00058 set { this.attributes = value; } 00059 } 00063 public DataRoleAttributes AddedAttributes 00064 { 00065 get { return this.addedAttributes; } 00066 } 00070 public DataRoleAttributes RemovedAttributes 00071 { 00072 get { return this.removedAttributes; } 00073 } 00077 public bool Modified 00078 { 00079 get { return this.modified; } 00080 set 00081 { 00082 if (!value) 00083 { 00084 this.RemovedAttributes.Clear(); 00085 this.AddedAttributes.Clear(); 00086 } 00087 this.modified = value; 00088 } 00089 } 00090 #endregion 00091 //********************************************************************* 00092 #region Public methods 00093 public bool ValidateNewAttribute(DataRoleAttribute newAttribute, ref string returnMessage) 00094 { 00095 DataRoleAttributes dataRoleAttributes = this.Attributes; 00096 if (this.Attributes.ContainsKey(newAttribute.ToString())) 00097 { 00098 returnMessage = RAIS.Common.Messages.DATA_ROLE_ATTRIBUTE_EXISTS; 00099 return false; 00100 } 00101 else 00102 if (this.RestricitonsConflict(newAttribute)) 00103 { 00104 returnMessage = RAIS.Common.Messages.DATA_ROLE_ATTRIBUTE_CONFLICT; 00105 return false; 00106 } 00107 else 00108 return true; 00109 } 00110 public bool ContainsRegionRestriction(string regionName) 00111 { 00112 foreach (DataRoleAttribute attribute in attributes.Values) 00113 { 00114 if (attribute.Region.Name == regionName) 00115 return true; 00116 } 00117 return false; 00118 } 00119 #endregion 00120 //********************************************************************* 00121 #region Constructors 00122 public DataRole() 00123 {} 00124 public DataRole(IDataRecord record) 00125 { 00126 this.ID = (int)record["PK Data Role ID"]; 00127 this.Name = record["Data Role Name"].ToString(); 00128 } 00129 #endregion 00130 //********************************************************************* 00131 #region Private helper methods 00132 00133 private bool RestricitonsConflict(DataRoleAttribute newAttribute) 00134 { 00135 DataRoleAttributes dataRoleAttributes = this.Attributes; 00136 foreach (DataRoleAttribute attribute in dataRoleAttributes.Values) 00137 { 00138 if (newAttribute.RestricitonsConflict(attribute)) 00139 { 00140 return true; 00141 } 00142 } 00143 return false; 00144 } 00145 00146 public bool AddAttribute(DataRoleAttribute newAttribute, ref string returnMessage) 00147 { 00148 bool success = this.ValidateNewAttribute(newAttribute, ref returnMessage); 00149 if (success) 00150 { 00151 //if (this.RemovedAttributes.ContainsKey(newAttribute.ToString())) 00152 // this.RemovedAttributes.Remove(newAttribute.ToString()); 00153 //else 00154 this.AddedAttributes.Add(newAttribute.ToString(), newAttribute); 00155 00156 this.Attributes.Add(newAttribute.ToString(), newAttribute); 00157 00158 this.Modified = true; 00159 } 00160 return success; 00161 } 00162 00163 public bool RemoveAttribute(DataRoleAttribute removedAttribute, ref string returnMessage) 00164 { 00165 if (this.AddedAttributes.ContainsKey(removedAttribute.ToString())) 00166 this.AddedAttributes.Remove(removedAttribute.ToString()); 00167 else 00168 this.RemovedAttributes.Add(removedAttribute.ToString(), removedAttribute); 00169 00170 this.Attributes.Remove(removedAttribute.ToString()); 00171 this.Modified = true; 00172 return true; 00173 } 00174 00175 public DataRoleAttribute GetAttributeByIndex(int index) 00176 { 00177 DataRoleAttribute attribute = null; 00178 00179 if (this.attributes.Count >= index) 00180 { 00181 int i = 0; 00182 foreach (KeyValuePair<string, DataRoleAttribute> kvp in this.attributes) 00183 { 00184 if (i == index) 00185 { 00186 attribute = kvp.Value; 00187 break; 00188 } 00189 i++; 00190 } 00191 } 00192 00193 return attribute; 00194 } 00195 #endregion 00196 } 00197 #endregion 00198 }